﻿Imports System.Data
Imports Microsoft.Data.Odbc
Imports System.Data.OracleClient
Public Class funciones1
    Public Shared Function LlenarDgv(ByVal querydgv As String) As DataTable
        Dim conexion2 As String = "Server=xe;Uid=redes;Pwd=redes;"
        'Creamos la conexion
        Dim oracon As New OracleConnection(conexion2)
        'Abrimos la conexion
        oracon.Open()
        'Creamos un comando
        Dim oraCommand As OracleCommand = New OracleCommand
        'Establecemos la conexion para el comando
        oraCommand.Connection = oracon
        'Escribimos el texto del comando
        oraCommand.CommandText = querydgv
        'Creamos un objeto adaptador
        Dim oraDataAdapter As New OracleDataAdapter
        oraDataAdapter.SelectCommand = oraCommand
        'Llenamos la tabla
        Dim dttabla As New DataTable
        oraDataAdapter.Fill(dttabla)

        Return dttabla


        oracon.Close()

    End Function
    Public Shared Function query(ByVal querydgv As String)
        Dim conexion2 As String = "Server=xe;Uid=redes;Pwd=redes;"
        'Creamos la conexion
        Dim oracon As New OracleConnection(conexion2)
        'Abrimos la conexion
        oracon.Open()
        'Creamos un comando
        Dim oraCommand As OracleCommand = New OracleCommand
        'Establecemos la conexion para el comando
        oraCommand.Connection = oracon
        'Escribimos el texto del comando
        oraCommand.CommandText = querydgv
        'Creamos un objeto adaptador
        Dim oraDataAdapter As New OracleDataAdapter
        oraDataAdapter.SelectCommand = oraCommand
        'Llenamos la tabla
        Dim dttabla As New DataTable
        oraDataAdapter.Fill(dttabla)

        Return dttabla


        oracon.Close()
    End Function

    Public Shared Sub query(ByRef combo As System.Windows.Forms.ComboBox, ByVal query As String, ByVal display As String) 'As DataTable
        Dim conexion2 As String = "Server=xe;Uid=redes;Pwd=redes;"
        'Creamos la conexion
        Dim oraCon As New OracleConnection(conexion2)
        'Abrimos la conexion
        oraCon.Open()
        'Creamos un comando
        Dim oraCommand As OracleCommand = New OracleCommand
        'Establecemos la conexion para el comando
        oraCommand.Connection = oraCon
        'Escribimos el texto del comando
        oraCommand.CommandText = query
        'Creamos un objeto adaptador
        Dim oraDataAdapter As New OracleDataAdapter
        oraDataAdapter.SelectCommand = oraCommand
        'Llenamos la tabla
        Dim dttabla As New DataTable
        oraDataAdapter.Fill(dttabla)
        combo.DataSource = dttabla
        'Establecemos el valor a mostrar y el valor a insertar

        combo.DisplayMember = display
        'Return dttabla
        oraCon.Close()
    End Sub
    Public Shared Sub llenarcombo(ByRef combo As System.Windows.Forms.ComboBox, ByVal query As String, ByVal valor As String, ByVal display As String) 'As DataTable
        Dim conexion2 As String = "Server=xe;Uid=redes;Pwd=redes;"
        'Creamos la conexion
        Dim oraCon As New OracleConnection(conexion2)
        'Abrimos la conexion
        oraCon.Open()
        'Creamos un comando
        Dim oraCommand As OracleCommand = New OracleCommand
        'Establecemos la conexion para el comando
        oraCommand.Connection = oraCon
        'Escribimos el texto del comando
        oraCommand.CommandText = query
        'Creamos un objeto adaptador
        Dim oraDataAdapter As New OracleDataAdapter
        oraDataAdapter.SelectCommand = oraCommand
        'Llenamos la tabla
        Dim dttabla As New DataTable
        oraDataAdapter.Fill(dttabla)
        combo.DataSource = dttabla
        'Establecemos el valor a mostrar y el valor a insertar
        combo.ValueMember = valor
        combo.DisplayMember = display

        oraCon.Close()
        Return
    End Sub

    Public Shared Function traersecuencia(ByVal querysecuencia As String, ByVal campo As String) As String
        Dim secuencia As String
        Dim iColumna As Integer

        Dim conexion2 As String = "Server=xe;Uid=redes;Pwd=redes;"
        'Creamos la conexion
        Dim oraCon As New OracleConnection(conexion2)
        'Abrimos la conexion
        oraCon.Open()
        'Creamos un comando
        Dim oraCommand As OracleCommand = New OracleCommand
        'Establecemos la conexion para el comando
        oraCommand.Connection = oraCon
        'Escribimos el texto del comando
        oraCommand.CommandText = querysecuencia
        Dim oraDataAdapter As New OracleDataAdapter
        oraDataAdapter.SelectCommand = oraCommand
        'Llenamos la tabla
        Dim dtData As New DataTable
        oraDataAdapter.Fill(dtData)
        Try
            iColumna = dtData.Columns(campo).Ordinal
            secuencia = dtData.Rows(0).ItemArray(iColumna).ToString()
        Catch ex As Exception
            secuencia = ""
        End Try

        If secuencia = "" Then
            Return "1"
        Else
            Return secuencia
        End If
        oraCon.Close()
    End Function

End Class

